package java11;

import java.util.List;
import java.util.stream.Collectors;

public class StringSample {

    public static void main(String[] args) {
        // =================================
        // 1. isBlank 判断字符是否为空串
        // =================================
        String str1 = " ";
        // ===> true
        boolean blank = str1.isBlank();
        // =================================
        // 2. repeat 复制
        // =================================
        String str2 = "Hi";
        // ===> HiHiHi
        String repeat = str2.repeat(3);
        // =================================
        // 3. strip 去除首尾空白字符
        // =================================
        String str3 = "     　Hello World  ";
        // trim 只能去除半角空白字符
        String trimStr = str3.trim();
        // strip 可以去除半角或全角的空白字符
        String stripStr = str3.strip();
        // stripLeading 去除首部的空白字符
        String stripLeading = str3.stripLeading();
        // stripTrailing 去除尾部的空白字符
        String stripTrailing = str3.stripTrailing();
        // =================================
        // 4. lines 以行终止符(\n或\r)分割获取字符
        // =================================
        String str4 = "This is the first line.\nThis is the second line.";
        // ===> This is the first line.
        // ===> This is the second line.
        List<String> lines = str4.lines().collect(Collectors.toList());
        lines.forEach(System.out::println);
    }

}